$(function() {
    //    if(window.screen.width==1024){
    //        $("div.container").css("width","990");
    //        $("div.header div.ad-1 img").attr("src","./images/header-ad-1-990.jpg");
    //    }

    //.header .top
    //鼠标点击更换城市后事件
    var $change_address = $("#change-address").on('mouseleave', function() {
        $change_address.find('div.pop').css('display', 'none');
    });
    $change_address.find('a.change').click(function() {
        $change_address.find('div.pop').css('display', 'block');
    });
    $change_address.find('div.pop div.p-close').hover(function() {
        $(this).css("cursor", "pointer");
    }, function() {
        $(this).css("cursor", "default");
    }).click(function() {
        $change_address.find('div.pop').css('display', 'none');
    });

    //.header .search
    //搜索框获得焦点
    var $search = $('#search');
    $search.find('input').val("路由器").on({
        'focus': function() {
            $search.find('.search-pop').css('display', 'block');
            $(this).val("");
        },
        'blur': function() {
            $(this).val("路由器");
            $search.find('.search-pop').css('display', 'none');
        }
    });
    $search.find('.search-top').on({
        'mouseleave': function() {
            $(this).find('.search-pop').css('display', 'none');
        }
    });

    //.mian .main-top .nav-ad
    //导航栏广告切换显示
    var nowStatus = 2;
    setInterval(function() {
        var a = $(".main .nav-right li.nav-ad a");
        if (nowStatus == 1) {
            a.css("background-image", "url(./images/nav-ad-1.png)").text("");
            nowStatus = 2;
        } else {
            a.css("background-image", "url(./images/nav-ad-2.png)").text("4.4570%");
            nowStatus = 1;
        }
    }, 1500, nowStatus);

    //.mian .main-top .slide
    //分类导航右侧幻灯片
    $(".main-top div.slide").slide({
        time: 3000,
        animate: 'style2'
    });

    //.mian .main-top .mscroll
    //图片导航切换
    var picture_nav_data = [
        "./images/main-top-content-1.jpg", "./images/main-top-content-2.jpg", "./images/main-top-content-3.jpg", "./images/main-top-content-4.jpg", "./images/main-top-content-5.jpg", "./images/main-top-content-6.jpg", "./images/main-top-content-7.jpg", "./images/main-top-content-8.jpg"
    ];
    $(".mscroll").picture_nav({
        data: picture_nav_data
    }).find('div:first').css('border-top', '0');

    //.mian .main-top .fastnav
    var $fastnav_pop = $('#fastnav-pop-tab1').tab();
    var $fastnav_content = $('#fastnav ul.fastnav-content');
    var $fastnav_pop_close = $('#fastnav span.close');
    $fastnav_content.find('li.top').on('mouseenter', function() {
        var now_index = $(this).index();
        $fastnav_content.animate({
            top: "-42px"
        }, 150, function() {
            $fastnav_pop_close.show();
            $fastnav_content.hide();
            $fastnav_pop.show().animate({
                top: "-1px"
            }, 150, function() {
                $fastnav_pop.display(now_index);
            });
        });
    });
    $fastnav_pop_close.on('click', function() {
        $fastnav_pop.animate({
            top: "-167px"
        }, 150, function() {
            $fastnav_pop_close.hide();
            $fastnav_pop.hide();
            $fastnav_content.show().animate({
                top: "0px"
            }, 150);
        });
    });
    $('#fastnav-pop-air-tab').tab();
    $('#fastnav-pop-game-tab').tab().display(2);

    //.mian .main-center .showcase
    $('.showcase ul.top li:first').swing({
        obj: '.picture img'
    }).nextAll().swing({
        obj: '.picture img'
    });

    //.mian .main-center .floor
    var floor = function(dom_id) {
        var $light = $(dom_id + ' .floor-light');
        $(window).on('scroll', function() {
            var top = $light.offset().top - $(window).scrollTop();
            if (top < $(window).scrollTop() && top > 0) {
                setTimeout(function() {
                    $light.addClass('light');
                }, 200);
            } else {
                $light.removeClass('light');
            }
        });
        var $tab = $(dom_id + ' .floor-center').tab();
        $tab.find('ul:first li').on('mouseenter', function() {
            var index = $(this).index();
            var left = "0px";
            if (index > 0) {
                left = index * 158 + "px";
            }
            $tab.find('.arrow').animate({
                left: left
            }, 200);
        });
        $(dom_id + ' .floor-center .slide').slide({
            animate: 'style1'
        });
        $(dom_id + ' .floor-right .slide2').slide();
        $(dom_id + ' .floor-right .slide').slide({
            animate: 'style1'
        });
    };
    floor('#floor-1f');
    floor('#floor-2f');
    floor('#floor-3f');
    floor('#floor-4f');
    floor('#floor-5f');
    floor('#floor-6f');
    floor('#floor-7f');
    floor('#floor-8f');

//鼠标移入后图片左右晃动
    $('#floor-3f .sale-list ul li .content').swing({
        begin: {
            marginLeft: '-15px'
        },
        obj: 'img'
    }).nextAll().swing({
        begin: {
            marginLeft: '-15px'
        },
        obj: 'img'
    });

//鼠标移入后周围图片半透明
    $('#floor-3f .sale-list ul li .content').on('mouseenter', function() {
        $(this).siblings().find('a').addClass('change');
        $(this).parent().siblings().find('a').addClass('change');
    }).on('mouseleave', function() {
        $(this).siblings().find('a').removeClass('change');
        $(this).parent().siblings().find('a').removeClass('change');
    });
    //鼠标移到图片上覆盖一层半透明动画效果
    //    $(".content li.c-li-1 a div").hover(function () {
    //        $(this).stop().animate({
    //            opacity: 0.4
    //        }, 400);
    //    }, function () {
    //        $(this).css("opacity", 0);
    //    });
});
